/**
 * <p>
 * 版权所有：中企动力
 * </p>
 * <p>
 * 未经本公司许可，不得以任何方式复制或使用本程序任何部分
 * </p>
 */
package com.ce.pms.report.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.report.queryvo.AdvanceGuarantySubentryStatisticsQueryVo;
import com.ce.pms.report.vo.AdvanceGuarantySubentryStatisticsVo;
import com.ce.pms.report.vo.BaseReportVo;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.DateUtil;

/**
 * 预收款抵扣分户分项统计表
 *
 *
 * @author <a href="mailto:i0o@live.cn">黄腾飞</a>
 * @Created 2008-11-14
 */

public class AdvanceGuarantySubentryStatisticsService extends BaseReportService
		implements ICEReportDataSetService {

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.ce.pms.report.service.BaseReportService#converToReportVoList(java
	 * .util.List)
	 */
	@Override
	protected List<BaseReportVo> converToReportVoList(List<Object[]> dataList) {
		List<BaseReportVo> voList = new ArrayList<BaseReportVo>();

		for (Object[] objTmp : dataList) {
			AdvanceGuarantySubentryStatisticsVo voTmp = new AdvanceGuarantySubentryStatisticsVo();

			voTmp.setHouseNumber((String) objTmp[0]);
			voTmp.setUserName((String) objTmp[1]);

			// 费用
			voTmp.setLastMonthPay(setValue(objTmp[2]));
			voTmp.setCurrentMonthPay(setValue(objTmp[3]));
			voTmp.setAdvanceCount(setValue(objTmp[4]));
			voTmp.setPayableMoney(setValue(objTmp[5]));
			voTmp.setActuallyMoney(setValue(objTmp[6]));
			voTmp.setOnticUpkeep(setValue(objTmp[7]));
			voTmp.setElectricityPay(setValue(objTmp[8]));
			voTmp.setOverheadExpenses(setValue(objTmp[9]));
			voTmp.setGarbagePay(setValue(objTmp[10]));
			voTmp.setSewagePay(setValue(objTmp[11]));
			voTmp.setWaterPay(setValue(objTmp[12]));
			voTmp.setBalance(setValue(objTmp[13]));

			voList.add(voTmp);
		}
		return voList;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.ce.report.service.ICEReportDataSetService#getReportDataSet(com.ce
	 * .report.vo.ReportsQueryBaseVo)
	 */
	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo queryVo)
			throws CEReportException {
		AdvanceGuarantySubentryStatisticsQueryVo agss = (AdvanceGuarantySubentryStatisticsQueryVo) queryVo;

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("period", DateUtil.convertDateToStr(agss.getMonthDate(), "yyyyMM"));
		map.put("precinctId",agss.getPrecinct());
		map.put("buildingId",agss.getBuilding() == null ? "%" : agss.getBuilding());

		List<Object[]> list = reportDao.getDataList("AdvanceGuarantySubentryStatistics", map);

		// 报表用数据集
		List<BaseReportVo> reportDate = converToReportVoList(list);

		return new CEReportDataSet(reportDate, getHeadInfo(agss.getMonthDate()));
	}

	/**
	 * @param queryVO
	 * @return
	 * @author <a href="mailto:i0o@live.cn">黄腾飞</a>
	 * @created 2008-11-28
	 */
	private Map<String, Object> getHeadInfo(Date month) {
		Map<String, Object> headerMap = new HashMap<String, Object>();
		headerMap.put("reportHeadStr", DateUtil.convertDateToStr(month,
				"(收费月份：yyyy年MM月份)"));
		return headerMap;
	}

}
